package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.testng.Assert.assertEquals;

import java.util.Random;

import org.testng.annotations.Test;

import com.example.fw.ContactHelper;
import com.example.utils.SortedListOf;

public class ContactRemovalTests extends TestBase {
	
	@Test
	
	public void deleteSomeContact() {
		ContactHelper contactHelper = app.getContactHelper();		
		//save old state
		SortedListOf<ContactData> oldContactList = contactHelper.getContacts();
		
		Random rnd = new Random();
		int index1 = rnd.nextInt(oldContactList.size()-1);
		//actions
		contactHelper.deleteContact(index1);

		//save new state
		SortedListOf<ContactData> newContactList = contactHelper.getContacts();
		//compare states
		assertEquals(newContactList.size(), oldContactList.size() - 1);
		
		assertThat(newContactList, equalTo(oldContactList.without(index1)));
	}
	

}
